package com.huabo.contract.service.impl;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.druid.util.StringUtils;
import com.hbfk.config.SystemStaticValue;
import com.hbfk.entity.DealUserToken;
import com.hbfk.entity.TblStaffUtil;
import com.hbfk.util.DateUtil;
import com.hbfk.util.JudgeRoleRight;
import com.hbfk.util.PageInfo;
import com.huabo.contract.config.DateBaseConfig;
import com.huabo.contract.controller.ZcSynchronizationController;
import com.huabo.contract.oracle.entity.TblAttachment;
import com.huabo.contract.oracle.entity.TblCirculation;
import com.huabo.contract.oracle.entity.TblContractAppendixsigning;
import com.huabo.contract.oracle.entity.TblContractSpnode;
import com.huabo.contract.oracle.entity.TblCounterpartBankinfo;
import com.huabo.contract.oracle.entity.TblCswlManagement;
import com.huabo.contract.oracle.entity.TblCyhwBudetgoods;
import com.huabo.contract.oracle.entity.TblCyhwProjectbudget;
import com.huabo.contract.oracle.entity.TblCyhwUnit;
import com.huabo.contract.oracle.entity.TblFlow;
import com.huabo.contract.oracle.entity.TblMyTask;
import com.huabo.contract.oracle.entity.TblProcessAnalusisUser;
import com.huabo.contract.oracle.entity.TblProcessAnalysis;
import com.huabo.contract.oracle.entity.TblStaff;
import com.huabo.contract.oracle.mapper.TblAttachmentMapper;
import com.huabo.contract.oracle.mapper.TblCirculationMapper;
import com.huabo.contract.oracle.mapper.TblContractAppendixsigningMapper;
import com.huabo.contract.oracle.mapper.TblCounterpartBankinfoMapper;
import com.huabo.contract.oracle.mapper.TblCyhwBudetgoodsMapper;
import com.huabo.contract.oracle.mapper.TblCyhwProjectbudgetMapper;
import com.huabo.contract.oracle.mapper.TblCyhwUnitMapper;
import com.huabo.contract.oracle.mapper.TblFlowMapper;
import com.huabo.contract.oracle.mapper.TblMyTaskMapper;
import com.huabo.contract.oracle.mapper.TblProcessAnalusisUserMapper;
import com.huabo.contract.oracle.mapper.TblProcessAnalysisMapper;
import com.huabo.contract.oracle.mapper.TblStaffMapper;
import com.huabo.contract.service.TblCirculationService;
import com.huabo.contract.service.TblCyhwProjectbudgetService;
import com.huabo.contract.util.DateUtils;
import com.huabo.contract.util.HttpClient;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;

@Service("tblCyhwProjectbudgetServiceImpl")
@Slf4j
public class TblCyhwProjectbudgetServiceImpl implements TblCyhwProjectbudgetService {

	@Resource
	private TblFlowMapper tblFlowMapper;
	
	@Resource
	private TblProcessAnalysisMapper tblProcessAnalysisMapper;
	
	@Resource
	private TblCyhwProjectbudgetMapper tblCyhwProjectbudgetMapper;
	
	@Resource
	private TblAttachmentMapper tblAttachmentMapper;
	
	@Resource
	private TblProcessAnalusisUserMapper tblProcessAnalusisUserMapper;
	
	@Resource
	private TblCirculationMapper tblCirculationMapper;
	
	@Resource
	private TblMyTaskMapper tblMytaskMapper;
	
	@Resource
	private TblCyhwUnitMapper tblCyhwUnitMapper;
	
	@Resource
	private TblContractAppendixsigningMapper tblContractAppendixsigningMapper;

	@Resource
	private TblCirculationService tblCirculationService;

	@Resource
	private TblCyhwBudetgoodsMapper tblCyhwBudetgoodsMapper;

	@Resource
	private TblCounterpartBankinfoMapper tblCounterpartBankinfoMapper;
	
	@Resource
	private ZcSynchronizationController  zcSynchronizationController;
    @Resource
    private TblStaffMapper tblStaffMapper;

	
	//相对方维护
	public Map<String,Object> findBudgetListByStaffOrg(String token, String flowId, String staffId, TblCyhwProjectbudget budget,Integer currentPage, Integer pageSize)
			throws Exception {
		Map<String,Object> resultMap = new HashMap<String, Object>(0);

		try {
			 TblStaffUtil staff = DealUserToken.parseUserToken(token);
			if(staff == null) {
				resultMap.put("code", "0");
				resultMap.put("msg", "用户已失效！");
				return resultMap;
			}

			TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
			Integer taskCount = tblProcessAnalysisMapper.getByModuel(flow.getFlownumber(),staff);

			PageInfo<TblCyhwProjectbudget> pageInfo = new PageInfo<TblCyhwProjectbudget>();
			if(pageSize != null) {
				pageInfo.setPageSize(pageSize);
			}
			pageInfo.setCurrentPage(currentPage);
			budget.setFlowid(flow.getFlowid());
			budget.setOrgid(staff.getCurrentOrg().getOrgid());
			budget.setRecordtype(flow.getFlownumber());
			pageInfo.setCondition(budget);

			pageInfo.setTlist(tblCyhwProjectbudgetMapper.selectListByPageInfo(pageInfo,staff,taskCount));
			pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.selectCountByPageInfo(pageInfo,staff,taskCount));
			resultMap.put("code", "1");
			resultMap.put("msg", "访问接口成功");
			resultMap.put("data", pageInfo);
			if(JudgeRoleRight.judgeRoleRight("合同黑名单管理员",staff.getRoleNames())){
				resultMap.put("isBlackAdmin", 0);//当前登录用户是黑名单管理员
	        }else {
	        	resultMap.put("isBlackAdmin", 1);//当前登录用户不是黑名单管理员
	        }
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultMap;
	}

	public Map<String, Object> loadAddOppositePartyInfo(String flowId, Integer contractId, String choiceSearch,
			String token, String staffId) throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			Map<String, Object> dateMap = new HashMap<String, Object>(0);

			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				SimpleDateFormat sdFormat = new SimpleDateFormat("yyyyMMSSS");
				Calendar cal = Calendar.getInstance();
				Date date = cal.getTime();
				String myTime = sdFormat.format(date);
				TblFlow flow = this.tblFlowMapper.findFlowInfoById(flowId);

				if ("HTGL003".equals(flow.getFlownumber()) && contractId != null) {
					//TblCyhwUnit unit = this.tblCyhwUnitService.getEntity(contractId);
					//mv.addObject("unit", unit);
				}
				Integer no = 0;
				Integer autoNum = this.tblCyhwProjectbudgetMapper.findAutoNumber(staff.getCurrentOrg().getOrgid());
				if (autoNum != null) {
					no = autoNum;
				}
				no = no + 1;
				String counterpartno = "CPNO-" + no;
				dateMap.put("counterpartno", counterpartno);
				dateMap.put("searchUrl", ((flow.getFlowmappingurl() == null) ? "/nbkz/cwgl/zcgl_main" : flow.getFlowmappingurl()));
				dateMap.put("code", flow.getFlownumber() + "_" + myTime);
				String createDate = DateUtil.getNowTime("yyyy-MM-dd");
				dateMap.put("createDate", createDate);
				dateMap.put("flowname", flow.getFlowname());
				dateMap.put("flowid", flow.getFlowid());
				dateMap.put("choiceSearch", choiceSearch);
				dateMap.put("staffInfo", staff);

				resultMap.put("code", "1");
				resultMap.put("msg", "访问接口成功");
				resultMap.put("data", dateMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			Map<String, Object> dateMap = new HashMap<String, Object>(0);

			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				SimpleDateFormat sdFormat = new SimpleDateFormat("yyyyMMSSS");
				Calendar cal = Calendar.getInstance();
				Date date = cal.getTime();
				String myTime = sdFormat.format(date);
				TblFlow flow = this.tblFlowMapper.findFlowInfoById(flowId);

				if ("HTGL003".equals(flow.getFlownumber()) && contractId != null) {
					//TblCyhwUnit unit = this.tblCyhwUnitService.getEntity(contractId);
					//mv.addObject("unit", unit);
				}
				Integer no = 0;
				Integer autoNum = this.tblCyhwProjectbudgetMapper.findAutoNumber(staff.getCurrentOrg().getOrgid());
				if (autoNum != null) {
					no = autoNum;
				}
				no = no + 1;
				String counterpartno = "CPNO-" + no;
				dateMap.put("counterpartno", counterpartno);
				dateMap.put("searchUrl", ((flow.getFlowmappingurl() == null) ? "/nbkz/cwgl/zcgl_main" : flow.getFlowmappingurl()));
				dateMap.put("code", flow.getFlownumber() + "_" + myTime);
				String createDate = DateUtil.getNowTime("yyyy-MM-dd");
				dateMap.put("createDate", createDate);
				dateMap.put("flowname", flow.getFlowname());
				dateMap.put("flowid", flow.getFlowid());
				dateMap.put("choiceSearch", choiceSearch);
				dateMap.put("staffInfo", staff);

				resultMap.put("code", "1");
				resultMap.put("msg", "访问接口成功");
				resultMap.put("data", dateMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		}
	}


	public Map<String, Object> SaveOppositeParty(TblCyhwProjectbudget tcpb, String attids, String staffId, String token,
			String flowId) throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);

			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
				tcpb.setRecordtype(flow.getFlownumber());
				tcpb.setCreateuser(staff.getStaffid());
				tcpb.setOrgid(staff.getCurrentOrg().getOrgid());
				tcpb.setFlowid(flow.getFlowid());
				Integer count = this.tblCyhwProjectbudgetMapper.selectRepearBudgetName(tcpb.getBudgetname(), staff.getCurrentOrg().getOrgid(), null);
				if (count > 0) {
					resultMap.put("code", "0");
					resultMap.put("msg", "相对方名称重复！");
					return resultMap;
				}
				this.tblCyhwProjectbudgetMapper.insertOppositePartyOld(tcpb);
				if (attids != null && !"".equals(attids)) {
					String[] ids = attids.split(",");
					for (String id : ids) {

						this.tblCyhwProjectbudgetMapper.insertAttmentRelation(id, tcpb.getBudgetid());
					}
				}
				resultMap.put("code", "1");
				resultMap.put("msg", "相对方保存成功！");
				resultMap.put("data", tcpb);
				//保存成功后推送相对方信息
				try {
					zcSynchronizationController.enterpriseperson(tcpb);
				} catch (Exception e) {
					// TODO: handle exception
					e.printStackTrace();
				}
				
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);

			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
				tcpb.setRecordtype(flow.getFlownumber());
				tcpb.setCreateuser(staff.getStaffid());
				tcpb.setOrgid(staff.getCurrentOrg().getOrgid());
				tcpb.setFlowid(flow.getFlowid());
				Integer count = this.tblCyhwProjectbudgetMapper.selectRepearBudgetName(tcpb.getBudgetname(), staff.getCurrentOrg().getOrgid(), null);
				if (count > 0) {
					resultMap.put("code", "0");
					resultMap.put("msg", "相对方名称重复！");
					return resultMap;
				}
				this.tblCyhwProjectbudgetMapper.insertOppositeParty(tcpb,null);
				if (attids != null && !"".equals(attids)) {
					String[] ids = attids.split(",");
					for (String id : ids) {

						this.tblCyhwProjectbudgetMapper.insertAttmentRelation(id, tcpb.getBudgetid());
					}
				}
				resultMap.put("code", "1");
				resultMap.put("msg", "相对方保存成功！");
				resultMap.put("data", tcpb);
				//保存成功后推送相对方信息
				zcSynchronizationController.enterpriseperson(tcpb);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		}
	}

	
	@Transactional(value="oracleDataSourceTransactionManager",rollbackFor = Exception.class,timeout=36000)
	public void removeOppsiteFile(String attid) throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			this.tblAttachmentMapper.deleteOppsiteFileRelatioin(attid);
			this.tblAttachmentMapper.deleteFileInfoById(attid);
		} else {
			this.tblAttachmentMapper.deleteOppsiteFileRelatioin(attid);
			this.tblAttachmentMapper.deleteFileInfoById(attid);
		}
	}

	
	public Integer findStatueById(Integer budgetId) throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			return this.tblCyhwProjectbudgetMapper.selectStatusByBudgetId(budgetId);
		} else {
			return this.tblCyhwProjectbudgetMapper.selectStatusByBudgetId(budgetId);
		}
	}

	
	public Map<String, Object> findOppsiteAllInfoById(String flowId, Integer budgetId, String token,
			String staffId) throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			Map<String, Object> dataMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
				TblCyhwProjectbudget budget = this.tblCyhwProjectbudgetMapper.selectAllInfoById(budgetId);
				List<TblAttachment> attList = this.tblCyhwProjectbudgetMapper.selectAllATT(budgetId);
				List<TblCounterpartBankinfo> bankInfoList = this.tblCounterpartBankinfoMapper.selectBankInfoByBugetId(budgetId);
				budget.setTblFlow(flow);
				//budget.setAttList(attList);
				//budget.setBankInfoList(bankInfoList);
				dataMap.put("attList", attList);
				dataMap.put("bankInfoList", bankInfoList);
				dataMap.put("budget", budget);
				resultMap.put("code", "1");
				resultMap.put("msg", "数据查询成功！");
				resultMap.put("data", dataMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			Map<String, Object> dataMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
				TblCyhwProjectbudget budget = this.tblCyhwProjectbudgetMapper.selectAllInfoById(budgetId);
				List<TblAttachment> attList = this.tblCyhwProjectbudgetMapper.selectAllATT(budgetId);
				List<TblCounterpartBankinfo> bankInfoList = this.tblCounterpartBankinfoMapper.selectBankInfoByBugetId(budgetId);
				budget.setTblFlow(flow);
				//budget.setAttList(attList);
				//budget.setBankInfoList(bankInfoList);
				dataMap.put("attList", attList);
				dataMap.put("bankInfoList", bankInfoList);
				dataMap.put("budget", budget);
				resultMap.put("code", "1");
				resultMap.put("msg", "数据查询成功！");
				resultMap.put("data", dataMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		}
	}

	
	public Map<String, Object> mengerOppsitePartyById(TblCyhwProjectbudget tcpb, String token, String staffId,
			String attids) throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);

			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				Integer count = this.tblCyhwProjectbudgetMapper.selectRepearBudgetName(tcpb.getBudgetname(), staff.getCurrentOrg().getOrgid(), tcpb.getBudgetid());
				if (count > 0) {
					resultMap.put("code", "0");
					resultMap.put("msg", "相对方名称重复！");
					return resultMap;
				}
				this.tblCyhwProjectbudgetMapper.updateOppositeInfoById(tcpb,null);
				if (attids != null && !"".equals(attids)) {
					String[] ids = attids.split(",");
					for (String id : ids) {
						this.tblCyhwProjectbudgetMapper.insertAttmentRelation(id, tcpb.getBudgetid());
					}
				}
				resultMap.put("code", "1");
				resultMap.put("msg", "相对方修改成功！");
				resultMap.put("data", tcpb);
				//修改成功后推送相对方信息
				zcSynchronizationController.enterpriseperson(tcpb);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);

			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				Integer count = this.tblCyhwProjectbudgetMapper.selectRepearBudgetName(tcpb.getBudgetname(), staff.getCurrentOrg().getOrgid(), tcpb.getBudgetid());
				if (count > 0) {
					resultMap.put("code", "0");
					resultMap.put("msg", "相对方名称重复！");
					return resultMap;
				}
				this.tblCyhwProjectbudgetMapper.updateOppositeInfoById(tcpb,null);
				if (attids != null && !"".equals(attids)) {
					String[] ids = attids.split(",");
					for (String id : ids) {
						this.tblCyhwProjectbudgetMapper.insertAttmentRelation(id, tcpb.getBudgetid());
					}
				}
				resultMap.put("code", "1");
				resultMap.put("msg", "相对方修改成功！");
				resultMap.put("data", tcpb);
				//修改成功后推送相对方信息
				zcSynchronizationController.enterpriseperson(tcpb);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		}
	}

	
	@Transactional(value="oracleDataSourceTransactionManager",rollbackFor = Exception.class,timeout=36000)
	public Map<String, Object> removeOppsitePartyInfo(String flowId, String token, String staffId, String budgetId)
			throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}
				Integer newBudgetId;
				if (budgetId.indexOf(",") != -1) {
					newBudgetId = Integer.parseInt(budgetId.split(",")[1]);
				} else {
					newBudgetId = Integer.parseInt(budgetId);
				}

				//this.tblCyhwProjectbudgetMapper.deleteOppsiteFileInfoByBudtetId(newBudgetId);
				this.tblCounterpartBankinfoMapper.deleteByBankInfo(newBudgetId);
				this.tblCyhwProjectbudgetMapper.deleteRelaFileInfo(newBudgetId);
				this.tblCyhwProjectbudgetMapper.deleteOppsiteInfoByBudtetId(newBudgetId);

				TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
				String url = "redirect:" + (flow.getFlowmappingurl() != null && !"".equals(flow.getFlowmappingurl()) ? flow.getFlowmappingurl() : "/nbkz/cwgl/zcgl_main") + "?flowid=" + flowId + "&flowname=" + flow.getFlownumber();
				resultMap.put("code", "1");
				resultMap.put("msg", "相对方删除成功！");
				resultMap.put("data", url);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}
				Integer newBudgetId;
				if (budgetId.indexOf(",") != -1) {
					newBudgetId = Integer.parseInt(budgetId.split(",")[1]);
				} else {
					newBudgetId = Integer.parseInt(budgetId);
				}

				//this.tblCyhwProjectbudgetMapper.deleteOppsiteFileInfoByBudtetId(newBudgetId);
				this.tblCounterpartBankinfoMapper.deleteByBankInfo(newBudgetId);
				this.tblCyhwProjectbudgetMapper.deleteRelaFileInfo(newBudgetId);
				this.tblCyhwProjectbudgetMapper.deleteOppsiteInfoByBudtetId(newBudgetId);

				TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
				String url = "redirect:" + (flow.getFlowmappingurl() != null && !"".equals(flow.getFlowmappingurl()) ? flow.getFlowmappingurl() : "/nbkz/cwgl/zcgl_main") + "?flowid=" + flowId + "&flowname=" + flow.getFlownumber();
				resultMap.put("code", "1");
				resultMap.put("msg", "相对方删除成功！");
				resultMap.put("data", url);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		}
	}

	
	public Map<String, Object> submitOppsitePartApproval(String budgetId, String token, String staffId,
			String examination, String flowId) throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil user = DealUserToken.parseUserToken(token);
				if (user == null) {
					resultMap.put("codes", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}
				if (budgetId.indexOf(",") != -1) {
					budgetId = budgetId.split(",")[1];
				}
				TblCyhwProjectbudget entity = this.tblCyhwProjectbudgetMapper.selectAllInfoById(Integer.parseInt(budgetId.toString()));

				if (entity.getInspectionstatus() != null && entity.getInspectionstatus() == 1) {
					resultMap.put("codes", "0");
					resultMap.put("msg", "流程审批中！");
					return resultMap;
				}
				if (entity.getInspectionstatus() != null && entity.getInspectionstatus() == 3) {
					resultMap.put("codes", "0");
					resultMap.put("msg", "流程已通过！");
					return resultMap;
				}
				if ((entity.getInspectionstatus() != null && entity.getInspectionstatus() == 4) || (entity.getInspectionstatus() != null && entity.getInspectionstatus() == 5) || (entity.getInspectionstatus() != null && entity.getInspectionstatus() == 6)) {
					resultMap.put("codes", "0");
					resultMap.put("msg", "流程已完成！");
					return resultMap;
				}
				TblFlow flow = this.tblFlowMapper.findFlowInfoById(flowId);


				List<TblProcessAnalysis> list = this.tblProcessAnalysisMapper.getByFlowSetting(flow.getSettingid());
				HashMap<String, Object> fields = new HashMap<String, Object>();
				if (list != null && list.size() > 0) {
					for (TblProcessAnalysis tblAnalysis : list) {
						TblProcessAnalusisUser analysisUser = this.tblProcessAnalusisUserMapper.findOnd(tblAnalysis.getAnalid().toString(), budgetId.toString());
						if (analysisUser == null) {
							analysisUser = new TblProcessAnalusisUser();
							analysisUser.setAnalid(tblAnalysis.getAnalid().toString());
							analysisUser.setFromid(budgetId.toString());
							analysisUser.setSpdate(new Date());
							if (tblAnalysis.getUserid() != null) {
								analysisUser.setStaffid(user.getRealname());
							} else {
								analysisUser.setStaffid(tblAnalysis.getRolename());
							}
                            //合同订立流程参数
                            //提交人参数
                            if (tblAnalysis.getUserid() != null && tblAnalysis.getUserid().equals("tcuserid")) {
                                fields.put("tcuserid", user.getStaffid().toString());
                                analysisUser.setStaffid(tblAnalysis.getRolename());
                            } else if (tblAnalysis.getUserid() != null && tblAnalysis.getUserid().equals("bmfzr")) {
                                //部门负责人参数
                                TblStaff bmfzr = tblStaffMapper.findByStaffManOrgs(user.getLinkDetp().getOrgid().toString());
                                if (bmfzr == null) {
                                    resultMap.put("code", "0");
                                    resultMap.put("msg", "部门负责人需配置！");
                                    return resultMap;
                                }
                                fields.put("bmfzr", bmfzr.getStaffid().toString());
                                System.out.println("bmfzr:" + bmfzr.getStaffid());
                            } else {
                                //除此之外的参数都设置为当前提交人
                                if (StrUtil.isNotBlank(tblAnalysis.getUserid())) {
                                    fields.put(tblAnalysis.getUserid(), user.getStaffid().toString());
                                }
                            }
							this.tblProcessAnalusisUserMapper.insertSetting(analysisUser);
						}else {
							 if (tblAnalysis.getUserid() != null && tblAnalysis.getUserid().equals("tcuserid")) {
	                                fields.put("tcuserid", user.getStaffid().toString());
	                            } else if (tblAnalysis.getUserid() != null && tblAnalysis.getUserid().equals("bmfzr")) {
	                                //部门负责人参数
	                                TblStaff bmfzr = tblStaffMapper.findByStaffManOrgs(user.getLinkDetp().getOrgid().toString());
	                                if (bmfzr == null) {
	                                    resultMap.put("code", "0");
	                                    resultMap.put("msg", "部门负责人需配置！");
	                                    return resultMap;
	                                }
	                                fields.put("bmfzr", bmfzr.getStaffid().toString());
	                                System.out.println("bmfzr:" + bmfzr.getStaffid());
	                            } else {
	                                //除此之外的参数都设置为当前提交人
	                                if (StrUtil.isNotBlank(tblAnalysis.getUserid())) {
	                                    fields.put(tblAnalysis.getUserid(), user.getStaffid().toString());
	                                }
	                            }
						}
					}
				}

				JSONObject jsonObject = JSONObject.fromObject(fields);
				Map<String, Object> map = HttpClient.startProcessAll(flow.getSettingid(), jsonObject.toString());
				String prcessresult = (String) map.get("result");
				String processInstanceId = (String) map.get("processInstanceId");
				String processDefinitionKey = (String) map.get("processDefinitionKey");
				TblCirculation cir = null;
				if (flow.getFlownumber().equals("HTGL001")) {
					cir = this.tblCirculationService.saveTblCirculationnew(flow.getFlowname(),entity.getBudgetname(), entity.getBudgetname(), TblProcessAnalysis.CYHW_URL_YSZC + budgetId, user.getStaffid(), processInstanceId, processDefinitionKey, budgetId.toString());
				} else if(flow.getFlownumber().equals("HTGL003")){//合同用印
					//合同用印要调用合同的名称+用印
					String name = "合同用印申请";
					if(entity.getRecordUnit().getContractname() != null && !"".equals(entity.getRecordUnit().getContractname())) {
						name = entity.getRecordUnit().getContractname()+"用印申请";
					}
					cir = this.tblCirculationService.saveTblCirculationnew(flow.getFlowname(), entity.getBudgetid().toString(), name, TblProcessAnalysis.CYHW_URL_YSZC + budgetId, user.getStaffid(), processInstanceId, processDefinitionKey, budgetId.toString());
				} else {
					cir = this.tblCirculationService.saveTblCirculationnew(flow.getFlowname(), entity.getBudgetid().toString(), entity.getBudgetname(), TblProcessAnalysis.CYHW_URL_YSZC + budgetId, user.getStaffid(), processInstanceId, processDefinitionKey, budgetId.toString());
				}
				if (prcessresult != null && prcessresult.equals("true")) {
					entity.setInspectionstatus(TblCswlManagement.STATE_SP);
					this.tblCyhwProjectbudgetMapper.updateInspectionStatus(entity);
					List<TblMyTask> tasks = HttpClient.findByTask("", user.getStaffid().toString(), 1, 10000);
					if (tasks != null && tasks.size() > 0) {
						for (TblMyTask task : tasks) {
							if (task.getProcessInstanceId().equals(processInstanceId)) {
								Map<String, Object> map1 = HttpClient.handleProcessJson(user.getStaffid().toString(), "通过", task.getTaskId());
								String result = (String) map1.get("result");
								if (result != null && "true".equals(result)) {
									String blande = "";
                                    //查询执行人
                                    String nextapprover = HttpClient.nextapprover(cir.getBusinesskey());
									TblProcessAnalysis analysis = this.tblProcessAnalysisMapper.findOndBytakdidstart(blande, flow.getSettingid());
                                    Integer number = 1;
                                    String usertaskid = analysis.getUsertaskid();
                                    Integer num = Integer.parseInt(usertaskid.substring(usertaskid.length() - 1, usertaskid.length())) + number;
                                    blande = usertaskid.substring(0, usertaskid.length() - 1) + num;
									TblProcessAnalysis analysis1 = this.tblProcessAnalysisMapper.findOndBytakdidstart(blande, flow.getSettingid());
									TblProcessAnalusisUser analysisUser = this.tblProcessAnalysisMapper.findOnd(analysis1.getAnalid().toString(), budgetId.toString());
									task.setFromid(budgetId.toString());
									task.setApprover(user.getRealname());
									task.setUsrid(user.getStaffid().toString());
									task.setExamination("提交审批");
									task.setProcessName(flow.getSettingid());
									if (user.getTrole() != null && user.getTrole().getRname() != null) {
										task.setApprovalrole(user.getTrole().getRname());
									}
									task.setApprovaldate(new Date());
									task.setResult("通过");
									task.setCirid(cir.getCyid().toString());
                                    if (nextapprover.contains("bmfzr")) {
                                        TblStaff bmfzr = tblStaffMapper.findByStaffManOrgs(user.getLinkDetp().getOrgid().toString());
                                        task.setHandle(bmfzr.getRealname());
                                    } else {
                                        task.setHandle(nextapprover);
                                    }
									task.setAnalid(analysisUser.getAnalid().toString());
									this.tblMytaskMapper.insertMyTaskSetting(task);
								}
							}
						}

					}
					resultMap.put("codes", "1");
					resultMap.put("msg", "审批已提交！");
				} else {
					resultMap.put("codes", "0");
					resultMap.put("msg", "流程提交失败！");
					log.error("发送审批失败");
				}
			} catch (Exception e) {
				log.error("发送审批失败");
				e.printStackTrace();
				resultMap.put("codes", "0");
				resultMap.put("msg", "流程提交失败！");
			}
			return resultMap;
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("codes", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				if (budgetId.indexOf(",") != -1) {
					budgetId = budgetId.split(",")[1];
				}
				TblCyhwProjectbudget entity = this.tblCyhwProjectbudgetMapper.selectAllInfoById(Integer.parseInt(budgetId.toString()));

				if (entity.getInspectionstatus() != null && entity.getInspectionstatus() == 1) {
					resultMap.put("codes", "0");
					resultMap.put("msg", "流程审批中！");
					return resultMap;
				}
				if (entity.getInspectionstatus() != null && entity.getInspectionstatus() == 3) {
					resultMap.put("codes", "0");
					resultMap.put("msg", "流程已通过！");
					return resultMap;
				}
				if ((entity.getInspectionstatus() != null && entity.getInspectionstatus() == 4) || (entity.getInspectionstatus() != null && entity.getInspectionstatus() == 5) || (entity.getInspectionstatus() != null && entity.getInspectionstatus() == 6)) {
					resultMap.put("codes", "0");
					resultMap.put("msg", "流程已完成！");
					return resultMap;
				}
				TblFlow flow = this.tblFlowMapper.findFlowInfoById(flowId);


				List<TblProcessAnalysis> list = this.tblProcessAnalysisMapper.getByFlowSetting(flow.getSettingid());
				HashMap<String, Object> fields = new HashMap<String, Object>();
				if (list != null && list.size() > 0) {
					for (TblProcessAnalysis tblAnalysis : list) {
						TblProcessAnalusisUser analysisUser = this.tblProcessAnalusisUserMapper.findOnd(tblAnalysis.getAnalid().toString(), budgetId.toString());
						if (analysisUser == null) {
							analysisUser = new TblProcessAnalusisUser();
							analysisUser.setAnalid(tblAnalysis.getAnalid().toString());
							analysisUser.setFromid(budgetId.toString());
							analysisUser.setSpdate(new Date());
							if (tblAnalysis.getUserid() != null) {
								analysisUser.setStaffid(staff.getRealname());
							} else {
								analysisUser.setStaffid(tblAnalysis.getRolename());
							}
							this.tblProcessAnalusisUserMapper.insertSetting(analysisUser);
						}
						if (tblAnalysis.getUserid() != null && !tblAnalysis.getUserid().equals("")) {
							fields.put(tblAnalysis.getUserid(), staff.getStaffid().toString());
						}
					}
				}

				JSONObject jsonObject = JSONObject.fromObject(fields);
				Map<String, Object> map = HttpClient.startProcessAll(flow.getSettingid(), jsonObject.toString());
				String prcessresult = (String) map.get("result");
				String processInstanceId = (String) map.get("processInstanceId");
				String processDefinitionKey = (String) map.get("processDefinitionKey");
				TblCirculation cir = null;
				if (flow.getFlownumber().equals("HTGL001")) {
					cir = this.tblCirculationService.saveTblCirculationnew(flow.getFlowname(), entity.getCounterpartno(), entity.getBudgetname(), TblProcessAnalysis.CYHW_URL_YSZC + budgetId, staff.getStaffid(), processInstanceId, processDefinitionKey, budgetId.toString());
				} else {
					cir = this.tblCirculationService.saveTblCirculationnew(flow.getFlowname(), entity.getBudgetid().toString(), entity.getBudgetname(), TblProcessAnalysis.CYHW_URL_YSZC + budgetId, staff.getStaffid(), processInstanceId, processDefinitionKey, budgetId.toString());
				}
				if (prcessresult != null && prcessresult.equals("true")) {
					entity.setInspectionstatus(TblCswlManagement.STATE_SP);
					this.tblCyhwProjectbudgetMapper.updateInspectionStatus(entity);
					List<TblMyTask> tasks = HttpClient.findByTask("", staff.getStaffid().toString(), 1, 1500);
					if (tasks != null && tasks.size() > 0) {
						for (TblMyTask task : tasks) {
							if (task.getProcessInstanceId().equals(processInstanceId)) {
								Map<String, Object> map1 = HttpClient.handleProcessJson(staff.getStaffid().toString(), "通过", task.getTaskId());
								String result = (String) map1.get("result");
								if (result != null && "true".equals(result)) {
									String blande = "";
									TblProcessAnalysis analysis = this.tblProcessAnalysisMapper.findOndBytakdidstart(blande, flow.getSettingid());
									Integer number = 1;
									String usertaskid = analysis.getUsertaskid();
									Integer num = Integer.parseInt(usertaskid.substring(usertaskid.length() - 1, usertaskid.length())) + number;
									blande = usertaskid.substring(0, usertaskid.length() - 1) + num;
									TblProcessAnalysis analysis1 = this.tblProcessAnalysisMapper.findOndBytakdidstart(blande, flow.getSettingid());
									TblProcessAnalusisUser analysisUser = this.tblProcessAnalysisMapper.findOnd(analysis1.getAnalid().toString(), budgetId.toString());
									task.setFromid(budgetId.toString());
									task.setApprover(staff.getRealname());
									task.setUsrid(staff.getStaffid().toString());
									task.setExamination(examination);
									task.setProcessName(flow.getSettingid());
									if (staff.getTrole() != null && staff.getTrole().getRname() != null) {
										task.setApprovalrole(staff.getTrole().getRname());
									}
									task.setApprovaldate(new Date());
									task.setResult("通过");
									task.setCirid(cir.getCyid().toString());
									if (analysisUser != null) {
										task.setHandle(analysisUser.getStaffid());
										task.setAnalid(analysisUser.getAnalid().toString());
									}
									this.tblMytaskMapper.insertMyTaskSetting(task);
								}
							}
						}

					}
					resultMap.put("codes", "1");
					resultMap.put("msg", "审批已提交！");
				} else {
					resultMap.put("codes", "0");
					resultMap.put("msg", "流程提交失败！");
					log.error("发送审批失败");
				}
			} catch (Exception e) {
				log.error("发送审批失败");
				e.printStackTrace();
				resultMap.put("codes", "0");
				resultMap.put("msg", "流程提交失败！");
			}
			return resultMap;
		}
	}

	
	public Map<String, Object> saveOppsitePartyBlack(Integer budgetId, String token, String staffId, Integer blackType,
			String datetext) throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}
				if (datetext != null) {
					this.tblCyhwProjectbudgetMapper.updateOppsitePartyBlack(budgetId, blackType, datetext);
				} else {
					this.tblCyhwProjectbudgetMapper.updateOppsitePartyBlackByDate(budgetId, blackType, datetext);
				}


				resultMap.put("code", "1");
				resultMap.put("msg", "加入黑名单成功！");
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}
				if (datetext != null) {
					this.tblCyhwProjectbudgetMapper.updateOppsitePartyBlack(budgetId, blackType, datetext);
				} else {
					this.tblCyhwProjectbudgetMapper.updateOppsitePartyBlackByDate(budgetId, blackType, datetext);
				}


				resultMap.put("code", "1");
				resultMap.put("msg", "加入黑名单成功！");
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		}
	}

	
	public Map<String, Object> removeBlackList(Integer budgetId, String token, String staffId) throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				this.tblCyhwProjectbudgetMapper.deleteOppsitePartyBlack(budgetId);

				resultMap.put("code", "1");
				resultMap.put("msg", "移除黑名单成功！");
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				this.tblCyhwProjectbudgetMapper.deleteOppsitePartyBlack(budgetId);

				resultMap.put("code", "1");
				resultMap.put("msg", "移除黑名单成功！");
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		}
	}

	
//	public Map<String, Object> finOppsiteWarningList(Integer pageNumber, TblCyhwProjectbudget tcpb, Integer isFlowdb,
//			String flowNumber, Integer view, Integer pageSize, String staffId, String token) throws Exception {
//		Map<String,Object> resultMap = new HashMap<String, Object>(0);
//		try {
//			TblStaffUtil staff = DealUserToken.parseUserToken(token);
//			if(staff == null) {
//				resultMap.put("code", "0");
//				resultMap.put("msg", "用户已失效！");
//				return resultMap;
//			}
//
//			PageInfo<TblCyhwProjectbudget> pageInfo = new PageInfo<TblCyhwProjectbudget>();
//
//			pageInfo.setCurrentPage(pageNumber);
//			pageInfo.setPageSize(pageSize);
//
//			TblFlow flow = tblFlowMapper.findFlowInfoByFlowNumber(flowNumber,staff.getCurrentOrg().getOrgid());
//			tcpb.setOrgid(staff.getCurrentOrg().getOrgid());
//			tcpb.setRecordtype(flow.getFlownumber());
//
//			Integer taskCount = tblProcessAnalysisMapper.getByModuel(flow.getFlownumber(),staff);
//				/**
//				 * 相对方管理
//				 */
//				pageInfo.setCondition(tcpb);
//				if("HTGL001".equals(flow.getFlownumber()) || "HTGL003".equals(flow.getFlownumber()) || "HTGL004".equals(flow.getFlownumber()) || "HTGL006".equals(flow.getFlownumber())) {
//					if(staff.getTrole()!=null && "合同管理员".equals(staff.getTrole().getRname())) {
//						taskCount = 0;
//					}
//				}
//
//				pageInfo.setTlist(tblCyhwProjectbudgetMapper.selectListByPageInfo(pageInfo,staff,taskCount));
//				pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.selectCountByPageInfo(pageInfo,staff,taskCount));
//
//
//				//关联合同数量+履约数量
//				List<TblCyhwProjectbudget> tlist = pageInfo.getTlist();
//				List<TblCyhwProjectbudget> budgetlist = new ArrayList<TblCyhwProjectbudget>();
//				Integer contractCount = 0;
//				Integer spNodeCount = 0;
//				for (TblCyhwProjectbudget tblCyhwProjectrBudget : tlist) {
//					contractCount =  this.tblCyhwUnitMapper.selectListByBudgetId(tblCyhwProjectrBudget.getBudgetid());
//					spNodeCount = this.tblCyhwProjectbudgetMapper.selectListByXdf(tblCyhwProjectrBudget.getBudgetid());
//					tblCyhwProjectrBudget.setUnitCount(contractCount);
//					tblCyhwProjectrBudget.setPerformanceCount(spNodeCount);
//					budgetlist.add(tblCyhwProjectrBudget);
//				}
//				pageInfo.setTlist(budgetlist);
//
////			//为页面查找区域显隐藏赋值
////			if(choiceSearch == null || "".equals(choiceSearch)) {
////				choiceSearch = "hide";
////			}
////			;
//			Map<String,Object> dataMap = new HashMap<String,Object>(0);
//			resultMap.put("data", pageInfo);
//			resultMap.put("flow", flow);
//			resultMap.put("code", "1");
//			resultMap.put("msg", "接口访问成功！");
//			//resultMap.put("data", dataMap);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		return resultMap;
//	}

	
	public Map<String, Object> findOppsiteBlackList(Integer pageNumber, TblCyhwProjectbudget tcpb, String flowNumber,
			Integer pageSize, String staffId, String token,String choose) throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}
				boolean taskCount = tblProcessAnalysisMapper.getByModu("HTGL001", staff);
				/**
				 * 相对方管理
				 */
				PageInfo<TblCyhwProjectbudget> pageInfo = new PageInfo<TblCyhwProjectbudget>();
				pageInfo.setCurrentPage(pageNumber);
				pageInfo.setPageSize(pageSize);

				tcpb.setRecordtype("HTGL001");
				tcpb.setOrgid(staff.getCurrentOrg().getOrgid());
				if (!"".equals(choose) && choose != null) {
					tcpb.setBudgetname(choose);
				}
				tcpb.setBlacktype(3);
				pageInfo.setCondition(tcpb);
				if (JudgeRoleRight.judgeRoleRight("合同管理员", staff.getRoleNames())) {
						taskCount = false;
				}
				
				pageInfo.setTlist(tblCyhwProjectbudgetMapper.selectOppsiteBlackList(pageInfo, staff, taskCount));
				pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.selectOppsiteBlackListCount(pageInfo,staff, taskCount));
				
				resultMap.put("data", pageInfo);
				resultMap.put("code", "1");
				resultMap.put("msg", "数据访问成功");
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}
				String flowid = "622322";
				TblFlow flow = tblFlowMapper.findByFlowid(flowid);
				boolean taskCount = tblProcessAnalysisMapper.getByModu(flow.getFlownumber(), staff);
				/**
				 * 相对方管理
				 */
				PageInfo<TblCyhwProjectbudget> pageInfo = new PageInfo<TblCyhwProjectbudget>();
				pageInfo.setCurrentPage(pageNumber);
				pageInfo.setPageSize(pageSize);

				tcpb.setFlowid(flow.getFlowid());
				tcpb.setOrgid(staff.getCurrentOrg().getOrgid());
				if (!"".equals(choose) && choose != null) {
					tcpb.setBudgetname(choose);
				}
				tcpb.setBlacktype(3);
				pageInfo.setCondition(tcpb);
				if ("HTGL001".equals(flow.getFlownumber()) || "HTGL003".equals(flow.getFlownumber()) || "HTGL004".equals(flow.getFlownumber()) || "HTGL006".equals(flow.getFlownumber())) {
					if (JudgeRoleRight.judgeRoleRight("合同管理员",staff.getRoleNames())) {
						taskCount = false;
					}
				}
				/*if (taskCount) {
					pageInfo.setTlist(tblCyhwProjectbudgetMapper.selectListByPageInfoFlowidTask(pageInfo, staff, taskCount, flowid));
					pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.selectListByPageInfoFlowidTaskCo(staff, taskCount, flowid));
				} else {
					pageInfo.setTlist(tblCyhwProjectbudgetMapper.selectCountByPageInfoStaffTaskCount(pageInfo, staff, flowid));
					pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.selectCountByPageInfoStaffTaskCo(staff, flowid));
				}*/


				//Map<String,Object> dataMap = new HashMap<String,Object>(0);
				resultMap.put("data", pageInfo);
				//resultMap.put("flow", flow);
				resultMap.put("code", "1");
				resultMap.put("msg", "数据访问成功");
				//resultMap.put("dataMap", dataMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		}
	}

	
	public List<TblCyhwProjectbudget> blacklistExport(BigDecimal orgid) throws Exception {
		List<TblCyhwProjectbudget> objList = null;
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			objList = this.tblCyhwProjectbudgetMapper.selectBlackList(orgid);
			return objList;
		} else {
			objList = this.tblCyhwProjectbudgetMapper.selectBlackList(orgid);
			return objList;
		}
	}


	public Map<String, Object> findOppsiteProcessInfo(String budgetId, String cateId, String v, String flowid,String tId, String staffId, String token) throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			Map<String, Object> dataMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				TblCyhwProjectbudget budget = this.tblCyhwProjectbudgetMapper.selectAllInfoById(Integer.parseInt(budgetId));
				 
				TblCirculation cy = this.tblCirculationMapper.selectCiculaInfoById(budgetId);

				List<TblMyTask> list = null;
				if (staff.getTrole() != null && staff.getTrole().getRname() != null) {
					dataMap.put("rolename", staff.getTrole().getRname());
					list = HttpClient.findByTask(staff.getTrole().getRname(), staff.getStaffid().toString(), 1, 10000);
				} else {
					list = HttpClient.findByTask("", staff.getStaffid().toString(), 1, 1500);
				}
				if (list != null && list.size() > 0) {
					Map<String, Object> map = null;
					String resultData = null;
					String[] results = null;
					for (TblMyTask myTask : list) {
						if (cy != null && myTask.getProcessInstanceId().equals(cy.getBusinesskey())) {
							map = HttpClient.lczxProcessJson(myTask.getTaskId());
							resultData = (String) map.get("data");
							results = resultData.replace("\"", "").split(",");
							if (results.length > 0 && !results[0].equals("")) {
								List<String> stringB = Arrays.asList(results);
								dataMap.put("results", stringB);
								dataMap.put("number", stringB.size());
							} else {
								dataMap.put("results", null);
								dataMap.put("number", 0);
							}
							dataMap.put("task", myTask);
							break;
						}
					}

				}
				if (budget.getRecordUnit() != null) {
					TblCyhwUnit tcu = this.tblCyhwUnitMapper.selectAllInfoById(budget.getRecordUnit().getContractid());
					List<TblContractAppendixsigning> signingList = this.tblContractAppendixsigningMapper.findFileListByContractId(tcu.getContractid());
					tcu.setSignList(signingList);
					budget.setRecordUnit(tcu);
				}
				//相对方外键
				if (budget.getRecordconcat() != null) {
					TblCyhwProjectbudget tcpb1 = this.tblCyhwProjectbudgetMapper.selectAllInfoById(budget.getRecordconcat());
					budget.setParentBudget(tcpb1);
				}
				if (flowid == null) {
					flowid = budget.getFlowInfo().getFlowid().toString();
				}
				TblFlow flow = this.tblFlowMapper.findFlowInfoById(flowid);
				dataMap.put("cy", cy);
				dataMap.put("cateId", cateId);
				dataMap.put("flow", flow);
				dataMap.put("oppsite", budget);
				dataMap.put("v", v);
				dataMap.put("flow", flow);

				resultMap.put("code", "1");
				resultMap.put("msg", "数据访问成功");
				resultMap.put("data", dataMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			Map<String, Object> dataMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				TblCyhwProjectbudget budget = this.tblCyhwProjectbudgetMapper.selectAllInfoById(Integer.parseInt(budgetId));

				TblCirculation cy = this.tblCirculationMapper.selectCiculaInfoById(tId);

				List<TblMyTask> list = null;
				if (staff.getTrole() != null && staff.getTrole().getRname() != null) {
					dataMap.put("rolename", staff.getTrole().getRname());
					list = HttpClient.findByTask(staff.getTrole().getRname(), staff.getStaffid().toString(), 1, 1500);
				} else {
					list = HttpClient.findByTask("", staff.getStaffid().toString(), 1, 1500);
				}
				if (list != null && list.size() > 0) {
					Map<String, Object> map = null;
					String resultData = null;
					String[] results = null;
					for (TblMyTask myTask : list) {
						if (cy != null && myTask.getProcessInstanceId().equals(cy.getBusinesskey())) {
							map = HttpClient.lczxProcessJson(myTask.getTaskId());
							resultData = (String) map.get("data");
							results = resultData.replace("\"", "").split(",");
							if (results.length > 0 && !results[0].equals("")) {
								List<String> stringB = Arrays.asList(results);
								dataMap.put("results", stringB);
								dataMap.put("number", stringB.size());
							} else {
								dataMap.put("results", null);
								dataMap.put("number", 0);
							}
							dataMap.put("task", myTask);
							break;
						}
					}

				}
				if (budget.getRecordUnit() != null) {
					TblCyhwUnit tcu = this.tblCyhwUnitMapper.selectAllInfoById(budget.getRecordUnit().getContractid());
					List<TblContractAppendixsigning> signingList = this.tblContractAppendixsigningMapper.findFileListByContractId(tcu.getContractid());
					tcu.setSignList(signingList);
					budget.setRecordUnit(tcu);
				}
				//相对方外键
				if (budget.getRecordconcat() != null) {
					TblCyhwProjectbudget tcpb1 = this.tblCyhwProjectbudgetMapper.selectAllInfoById(budget.getRecordconcat());
					budget.setParentBudget(tcpb1);
				}
				if (flowid == null) {
					flowid = budget.getFlowInfo().getFlowid().toString();
				}
				TblFlow flow = this.tblFlowMapper.findFlowInfoById(flowid);
				dataMap.put("cy", cy);
				dataMap.put("cateId", cateId);
				dataMap.put("flow", flow);
				dataMap.put("oppsite", budget);
				dataMap.put("v", v);
				dataMap.put("flow", flow);

				resultMap.put("code", "1");
				resultMap.put("msg", "数据访问成功");
				resultMap.put("data", dataMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		}
	}

	
	public Map<String, Object> viewOppsiteActiviti(String budgetId, String view, String taskId, String flowid,
			String flowname, String cateId, String staffId, String token) throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				TblCyhwProjectbudget budget = this.tblCyhwProjectbudgetMapper.selectAllInfoById(Integer.parseInt(budgetId));
				List<TblCounterpartBankinfo> bankInfoList = this.tblCounterpartBankinfoMapper.selectBankInfoByBugetId(Integer.parseInt(budgetId));
				List<TblMyTask> list = this.tblMytaskMapper.selectByFormId(budgetId);
				Map<String, Object> dataMap = new HashMap<String, Object>(0);
				dataMap.put("budget", budget);
				dataMap.put("taskId", taskId);
				dataMap.put("taskList", list);
				dataMap.put("view", view);
				dataMap.put("cateId", cateId);
				dataMap.put("flowid", flowid);
				dataMap.put("flowname", flowid);
				dataMap.put("bankInfoList", bankInfoList);
				dataMap.put("url", HttpClient.jkurl + taskId);
				resultMap.put("code", "1");
				resultMap.put("msg", "数据访问成功");
				resultMap.put("data", dataMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				TblCyhwProjectbudget budget = this.tblCyhwProjectbudgetMapper.selectAllInfoById(Integer.parseInt(budgetId));
				List<TblCounterpartBankinfo> bankInfoList = this.tblCounterpartBankinfoMapper.selectBankInfoByBugetId(Integer.parseInt(budgetId));
				List<TblMyTask> list = this.tblMytaskMapper.selectByFormId(budgetId);
				Map<String, Object> dataMap = new HashMap<String, Object>(0);
				dataMap.put("budget", budget);
				dataMap.put("taskId", taskId);
				dataMap.put("taskList", list);
				dataMap.put("view", view);
				dataMap.put("cateId", cateId);
				dataMap.put("flowid", flowid);
				dataMap.put("flowname", flowid);
				dataMap.put("bankInfoList", bankInfoList);
				dataMap.put("url", HttpClient.jkurl + taskId);
				resultMap.put("code", "1");
				resultMap.put("msg", "数据访问成功");
				resultMap.put("data", dataMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		}
	}

	@Transactional(value="oracleDataSourceTransactionManager",rollbackFor = Exception.class,timeout=36000)
	public Map<String, Object> blOppsiteProcessyszc(String budgetId, String taskId,String processDefinitionId, String processInstanceId, String transitionName, String examination,
			String cyId, String token, String staffId) throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				TblCyhwProjectbudget budget = this.tblCyhwProjectbudgetMapper.selectAllInfoById(Integer.parseInt(budgetId));
				if (taskId != null && !taskId.equals("")) {
					Map<String, Object> map = HttpClient.handleProcessJson(staff.getStaffid().toString(), transitionName, taskId);
					String mapResult = (String) map.get("result");
					if (mapResult != null && mapResult.equals("true")) {
						TblMyTask task = new TblMyTask();
						TblMyTask oldtask = this.tblMytaskMapper.selectByFormIdReturnUnique(budgetId.toString());
						TblProcessAnalysis findOnd = null;
						if (oldtask == null) {
							findOnd = this.tblProcessAnalysisMapper.findOndBytakdid("");
						} else {
							findOnd = this.tblProcessAnalysisMapper.findOndByAnalid(oldtask.getAnalid());
						}
						Integer number = 1;
						String usertaskid = findOnd.getUsertaskid();
						Integer num = Integer.parseInt(usertaskid.substring(usertaskid.length() - 1, usertaskid.length())) + number;
						String blande = usertaskid.substring(0, usertaskid.length() - 1) + num;
						TblProcessAnalysis analysis = null;
						if (transitionName != null && transitionName.equals("退回")) {
							analysis = this.tblProcessAnalysisMapper.findOndBytakdidstart("", findOnd.getProcessname());
						} else {
							analysis = this.tblProcessAnalysisMapper.findOndBytakdidAnId(blande, findOnd.getProcessname());
						}
						TblProcessAnalusisUser analysisUser = null;
						if (analysis != null && analysis.getAnalid() != null) {
							analysisUser = this.tblProcessAnalusisUserMapper.findOnd(analysis.getAnalid().toString(), budgetId.toString());
						}
						TblCirculation circulation = this.tblCirculationMapper.selectCiculaInfoById(cyId);
						task.setApprovaldate(new Date());
						if (staff.getTrole() != null && staff.getTrole().getRname() != null) {
							task.setApprovalrole(staff.getTrole().getRname());
						}
						task.setApprover(staff.getRealname());
						task.setExamination(examination);
						task.setFromid(budgetId.toString());
						task.setProcessDefinitionId(processDefinitionId);
						task.setUsrid(staff.getStaffid().toString());
						task.setCirid(cyId);
						task.setResult(transitionName);
						task.setProcessName(oldtask.getProcessName());
						task.setTaskId(taskId);
						task.setProcessInstanceId(processInstanceId);
						if (analysis == null || analysisUser == null) {
							task.setHandle("无");
							circulation.setCystate("已完成");
							budget.setInspectionstatus(TblCswlManagement.STATE_WC);
						} else {
							task.setHandle(analysisUser.getStaffid());
							task.setAnalid(analysis.getAnalid().toString());
						}

						if (budget.getInspectionstatus() == 2) {
							budget.setInspectionstatus(TblCswlManagement.STATE_SP);
						}
						if (transitionName != null && transitionName.equals("退回")) {
							circulation.setCystate("需调整");
							budget.setInspectionstatus(TblCswlManagement.STATE_TZ);
						}
						if (transitionName != null && transitionName.equals("终止")) {
							circulation.setCystate("终止");
							task.setHandle("无");
							budget.setInspectionstatus(TblCswlManagement.STATE_ZZ);
						}
						this.tblMytaskMapper.insertMyTaskSetting(task);
						this.tblCirculationMapper.updateCirculationInfoById(circulation);
						this.tblCyhwProjectbudgetMapper.updateInspectionStatus(budget);
						resultMap.put("code", "1");
						resultMap.put("msg", "流程办理成功！");
					}
				}

			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				TblCyhwProjectbudget budget = this.tblCyhwProjectbudgetMapper.selectAllInfoById(Integer.parseInt(budgetId));
				if (taskId != null && !taskId.equals("")) {
					Map<String, Object> map = HttpClient.handleProcessJson(staff.getStaffid().toString(), transitionName, taskId);
					String mapResult = (String) map.get("result");
					if (mapResult != null && mapResult.equals("true")) {
						TblMyTask task = new TblMyTask();
						TblMyTask oldtask = this.tblMytaskMapper.selectByFormIdReturnUnique(budgetId.toString());
						TblProcessAnalysis findOnd = null;
						if (oldtask == null) {
							findOnd = this.tblProcessAnalysisMapper.findOndBytakdid("");
						} else {
							findOnd = this.tblProcessAnalysisMapper.findOndByAnalid(oldtask.getAnalid());
						}
						Integer number = 1;
						String usertaskid = findOnd.getUsertaskid();
						Integer num = Integer.parseInt(usertaskid.substring(usertaskid.length() - 1, usertaskid.length())) + number;
						String blande = usertaskid.substring(0, usertaskid.length() - 1) + num;
						TblProcessAnalysis analysis = null;
						if (transitionName != null && transitionName.equals("退回")) {
							analysis = this.tblProcessAnalysisMapper.findOndBytakdidstart("", findOnd.getProcessname());
						} else {
							analysis = this.tblProcessAnalysisMapper.findOndBytakdidAnId(blande, findOnd.getProcessname());
						}
						TblProcessAnalusisUser analysisUser = null;
						if (analysis != null && analysis.getAnalid() != null) {
							analysisUser = this.tblProcessAnalusisUserMapper.findOnd(analysis.getAnalid().toString(), budgetId.toString());
						}
						TblCirculation circulation = this.tblCirculationMapper.selectCiculaInfoById(cyId);
						task.setApprovaldate(new Date());
						if (staff.getTrole() != null && staff.getTrole().getRname() != null) {
							task.setApprovalrole(staff.getTrole().getRname());
						}
						task.setApprover(staff.getRealname());
						task.setExamination(examination);
						task.setFromid(budgetId.toString());
						task.setProcessDefinitionId(processDefinitionId);
						task.setUsrid(staff.getStaffid().toString());
						task.setCirid(cyId);
						task.setResult(transitionName);
						task.setProcessName(oldtask.getProcessName());
						task.setTaskId(taskId);
						task.setProcessInstanceId(processInstanceId);
						if (analysis == null || analysisUser == null) {
							task.setHandle("无");
							circulation.setCystate("已完成");
							budget.setInspectionstatus(TblCswlManagement.STATE_WC);
						} else {
							task.setHandle(analysisUser.getStaffid());
							task.setAnalid(analysis.getAnalid().toString());
						}

						if (budget.getInspectionstatus() == 2) {
							budget.setInspectionstatus(TblCswlManagement.STATE_SP);
						}
						if (transitionName != null && transitionName.equals("退回")) {
							circulation.setCystate("需调整");
							budget.setInspectionstatus(TblCswlManagement.STATE_TZ);
						}
						if (transitionName != null && transitionName.equals("终止")) {
							circulation.setCystate("终止");
							task.setHandle("无");
							budget.setInspectionstatus(TblCswlManagement.STATE_ZZ);
						}
						this.tblMytaskMapper.insertMyTaskSetting(task);
						this.tblCirculationMapper.updateCirculationInfoById(circulation);
						this.tblCyhwProjectbudgetMapper.updateInspectionStatus(budget);
						resultMap.put("code", "1");
						resultMap.put("msg", "流程办理成功！");
					}
				}

			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		}
	}

    @Override
    public void invoiceCounterpartInfoListByPageInfo(PageInfo<TblCyhwProjectbudget> pageInfo, TblCyhwProjectbudget tcpb) {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			pageInfo.setTlist(tblCyhwProjectbudgetMapper.findCollectionChoiceContractPid(pageInfo, tcpb));
			pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.findCollectionChoiceContractPidCount(tcpb));
			resultMap.put("code", "1");
			resultMap.put("msg", "访问接口成功");
			resultMap.put("data", pageInfo);
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			pageInfo.setTlist(tblCyhwProjectbudgetMapper.findCollectionChoiceContractPid(pageInfo, tcpb));
			pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.findCollectionChoiceContractPidCount(tcpb));
			resultMap.put("code", "1");
			resultMap.put("msg", "访问接口成功");
			resultMap.put("data", pageInfo);
		}
    }

	@Override
	public Map<String, Object> insertOrUpdateBybudget(TblCyhwProjectbudget tcpb, String token, String attids,String flowId,Integer sealorgid) {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}
				
				Integer contractId = tcpb.getRecordparent();
				TblCyhwUnit unit = this.tblCyhwUnitMapper.getEntity(contractId);
				if("2".equals(unit.getContractstatus()+"")) {
					resultMap.put("code", "0");
					resultMap.put("msg", "请在“我的待办”处理需调整的用印信息！");
				}
				
				TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
				tcpb.setRecordtype(flow.getFlownumber());
				tcpb.setCreateuser(staff.getStaffid());
				tcpb.setOrgid(staff.getCurrentOrg().getOrgid());
				tcpb.setFlowid(flow.getFlowid());
				if (tcpb.getBudgetid() != null) {
					this.tblCyhwProjectbudgetMapper.updateOppositeInfoById(tcpb,sealorgid);
				} else {
					tcpb.setInspectionstatus(0);
					this.tblCyhwProjectbudgetMapper.insertOppositeParty(tcpb,sealorgid);
				}
				if (attids != null && !"".equals(attids)) {
					String[] ids = attids.split(",");
					for (String id : ids) {
						this.tblCyhwProjectbudgetMapper.insertAttmentRelation(id, tcpb.getBudgetid());
					}
				}
				resultMap.put("code", "1");
				resultMap.put("msg", "保存成功！");
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}
				TblFlow flow = tblFlowMapper.findFlowInfoById(flowId);
				tcpb.setRecordtype(flow.getFlownumber());
				tcpb.setCreateuser(staff.getStaffid());
				tcpb.setOrgid(staff.getCurrentOrg().getOrgid());
				tcpb.setFlowid(flow.getFlowid());
				if (tcpb.getBudgetid() != null) {
					this.tblCyhwProjectbudgetMapper.updateOppositeInfoById(tcpb,null);
				} else {
					this.tblCyhwProjectbudgetMapper.insertOppositeParty(tcpb,null);
				}
				if (attids != null && !"".equals(attids)) {
					String[] ids = attids.split(",");
					for (String id : ids) {
						this.tblCyhwProjectbudgetMapper.insertAttmentRelation(id, tcpb.getBudgetid());
					}
				}
				resultMap.put("code", "1");
				resultMap.put("msg", "保存成功！");
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		}
	}

    @Override
    public Map<String, Object> projectrBudgetToModify(BigDecimal flowId, Integer budgetId) {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			Map<String, Object> dataMap = new HashMap<String, Object>(0);
			try {
				TblCyhwProjectbudget tcpb = tblCyhwProjectbudgetMapper.findBybudgetId(budgetId);
				List<TblAttachment> attList = tblAttachmentMapper.findAttachmentListByBudgetId(budgetId);
				
				if (tcpb.getRecordparent() != null) {
					TblCyhwUnit tcu = tblCyhwUnitMapper.getEntity(tcpb.getRecordparent());
					dataMap.put("tcu", tcu);
					List<TblContractAppendixsigning> signingList = this.tblContractAppendixsigningMapper.findFileListByContractId(tcu.getContractid());
					dataMap.put("signingList", signingList);
				}
				//相对方外键
				if (tcpb.getRecordconcat() != null) {
					TblCyhwProjectbudget tcpb1 = tblCyhwProjectbudgetMapper.getEntity(tcpb.getRecordparent());
					dataMap.put("tcpb1", tcpb1);
				}
				
				
				dataMap.put("attList", attList);
				dataMap.put("tcpb", tcpb);
				dataMap.put("flowId", flowId);
				resultMap.put("code", "1");
				resultMap.put("msg", "成功！");
				resultMap.put("data", dataMap);

			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			Map<String, Object> dataMap = new HashMap<String, Object>(0);
			try {
				TblCyhwProjectbudget tcpb = tblCyhwProjectbudgetMapper.findBybudgetId(budgetId);
				List<TblAttachment> attList = tblAttachmentMapper.findAttachmentListByBudgetId(budgetId);
				dataMap.put("attList", attList);
				if (tcpb.getRecordparent() != null) {
					TblCyhwUnit tcu = tblCyhwUnitMapper.getEntity(tcpb.getRecordparent());
					dataMap.put("tcu", tcu);
					List<TblContractAppendixsigning> signingList = this.tblContractAppendixsigningMapper.findFileListByContractId(tcu.getContractid());
					dataMap.put("signingList", signingList);
				}
				//相对方外键
				if (tcpb.getRecordconcat() != null) {
					TblCyhwProjectbudget tcpb1 = tblCyhwProjectbudgetMapper.getEntity(tcpb.getRecordparent());
					dataMap.put("tcpb1", tcpb1);
				}
				dataMap.put("tcpb", tcpb);
				dataMap.put("flowId", flowId);
				resultMap.put("code", "1");
				resultMap.put("msg", "成功！");
				resultMap.put("data", dataMap);

			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		}
    }

	@Override
	public void insertOrUpdateBybudgetTcb(TblCyhwProjectbudget tcb) throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			tblCyhwProjectbudgetMapper.insertOppositeParty(tcb,null);
		} else {
			tblCyhwProjectbudgetMapper.insertOppositeParty(tcb,null);
		}
	}

    @Override
    public void updateTcb(TblCyhwProjectbudget tcb) throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			tblCyhwProjectbudgetMapper.updateOppositeInfoById(tcb,null);
		} else {
			tblCyhwProjectbudgetMapper.updateOppositeInfoById(tcb,null);
		}
    }

    @Override
    public TblCyhwProjectbudget findBudgetid(Integer budgetid) {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			return tblCyhwProjectbudgetMapper.getEntity(budgetid);
		} else {
			return tblCyhwProjectbudgetMapper.getEntity(budgetid);
		}
    }

    @Override
    public String removeOppsitePartyBlack(Integer budgetid) {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			String result = this.tblCyhwProjectbudgetMapper.excuteFunReturnUnique(budgetid);
			if (result != null) {
				this.tblCyhwProjectbudgetMapper.executeSql(budgetid, null);
				return "0";
			} else {
				return "1";
			}
		} else {
			String result = this.tblCyhwProjectbudgetMapper.excuteFunReturnUnique(budgetid);
			if (result != null) {
				this.tblCyhwProjectbudgetMapper.executeSql(budgetid, null);
				return "0";
			} else {
				return "1";
			}
		}
    }

    @Override
    public void findListByPageInfo(PageInfo<TblCyhwProjectbudget> pageInfo, BigDecimal orgid) {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			pageInfo.setTlist(tblCyhwProjectbudgetMapper.findListByPageInfoOrgid(pageInfo, orgid));
			pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.findListByPageInfoCount(orgid));
			resultMap.put("code", "1");
			resultMap.put("msg", "访问接口成功");
			resultMap.put("data", pageInfo);
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			pageInfo.setTlist(tblCyhwProjectbudgetMapper.findListByPageInfoOrgid(pageInfo, orgid));
			pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.findListByPageInfoCount(orgid));
			resultMap.put("code", "1");
			resultMap.put("msg", "访问接口成功");
			resultMap.put("data", pageInfo);
		}
    }

	@Override
	public void findListByPage(PageInfo<TblCyhwProjectbudget> pageInfo, String userid, BigDecimal orgid) {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			pageInfo.setTlist(tblCyhwProjectbudgetMapper.findListByPage(pageInfo, userid, orgid));
			pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.findListByPageCount(userid, orgid));
			resultMap.put("code", "1");
			resultMap.put("msg", "访问接口成功");
			resultMap.put("data", pageInfo);
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			pageInfo.setTlist(tblCyhwProjectbudgetMapper.findListByPage(pageInfo, userid, orgid));
			pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.findListByPageCount(userid, orgid));
			resultMap.put("code", "1");
			resultMap.put("msg", "访问接口成功");
			resultMap.put("data", pageInfo);
		}
	}

	@Override
	public boolean getByModuel(String flownumber, TblStaffUtil staff) {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			List<TblProcessAnalysis> list = this.tblProcessAnalysisMapper.getByModuelStaff(staff);
			return list != null && list.size() > 0;
		} else {
			List<TblProcessAnalysis> list = this.tblProcessAnalysisMapper.getByModuelStaff(staff);
			return list != null && list.size() > 0;
		}
	}

    @Override
    public void findListByPageInfoTcpb(PageInfo<TblCyhwProjectbudget> pageInfo, BigDecimal orgid, TblCyhwProjectbudget tcpb) {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			pageInfo.setTlist(tblCyhwProjectbudgetMapper.findListByPageInfoTcpb(pageInfo, orgid, tcpb));
			pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.findListByPageInfoTcpbCount(orgid, tcpb));
			resultMap.put("code", "1");
			resultMap.put("msg", "访问接口成功");
			resultMap.put("data", pageInfo);
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			pageInfo.setTlist(tblCyhwProjectbudgetMapper.findListByPageInfoTcpb(pageInfo, orgid, tcpb));
			pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.findListByPageInfoTcpbCount(orgid, tcpb));
			resultMap.put("code", "1");
			resultMap.put("msg", "访问接口成功");
			resultMap.put("data", pageInfo);
		}
    }

    @Override
    public void findListByPageTcpb(PageInfo<TblCyhwProjectbudget> pageInfo, String staffid, BigDecimal orgid, TblCyhwProjectbudget tcpb) {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			pageInfo.setTlist(tblCyhwProjectbudgetMapper.findListByPageTcpb(pageInfo, staffid, orgid, tcpb));
			pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.findListByPageTcpbCount(staffid, orgid, tcpb));
			resultMap.put("code", "1");
			resultMap.put("msg", "访问接口成功");
			resultMap.put("data", pageInfo);
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			pageInfo.setTlist(tblCyhwProjectbudgetMapper.findListByPageTcpb(pageInfo, staffid, orgid, tcpb));
			pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.findListByPageTcpbCount(staffid, orgid, tcpb));
			resultMap.put("code", "1");
			resultMap.put("msg", "访问接口成功");
			resultMap.put("data", pageInfo);
		}
    }

	@Override
	public Map<String, Object> finOppsiteWarningList(Integer pageNumber, TblCyhwProjectbudget tcpb, Integer isFlowdb,
			String flowNumber, Integer view, Integer pageSize, String staffId, String token) {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				PageInfo<TblCyhwProjectbudget> pageInfo = new PageInfo<TblCyhwProjectbudget>();

				if (pageSize != null) {
					pageInfo.setPageSize(pageSize);
				}
				if (pageNumber == null) {
					pageNumber = 1;
				}

				pageInfo.setCurrentPage(pageNumber);
				String flowid = "622322";
				TblFlow flow = tblFlowMapper.findById(flowid);
				//TblFlow flow = tblFlowMapper.findFlowInfoByFlowNumber(flowNumber,staff.getCurrentOrg().getOrgid());
				tcpb.setOrgid(staff.getCurrentOrg().getOrgid());
				tcpb.setRecordtype(flow.getFlownumber());
				pageInfo.setCondition(tcpb);
				Integer taskCount = tblProcessAnalysisMapper.getByModuel(flow.getFlownumber(), staff);
				/**
				 * 相对方管理
				 */
//				pageInfo.setCondition(tcpb);
//				if("HTGL001".equals(flow.getFlownumber()) || "HTGL003".equals(flow.getFlownumber()) || "HTGL004".equals(flow.getFlownumber()) || "HTGL006".equals(flow.getFlownumber())) {
//					if(staff.getTrole()!=null && "合同管理员".equals(staff.getTrole().getRname())) {
//						taskCount = 0;
//					}
//				}


				pageInfo.setTlist(tblCyhwProjectbudgetMapper.selectListByPageInfoFlowid(pageInfo, staff, taskCount, flowid));
//				pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.selectCountByPageInfo(pageInfo,staff,taskCount));
				pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.selectListByPageInfoFlowidCount(staff, taskCount, flowid));
				//pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.selectCountByPageInfoCount(staff,taskCount));
				//关联合同数量+履约数量
				List<TblCyhwProjectbudget> tlist = pageInfo.getTlist();
				List<TblCyhwProjectbudget> budgetlist = new ArrayList<TblCyhwProjectbudget>();
//				Integer contractCount = 0;
//				Integer spNodeCount = 0;
				for (TblCyhwProjectbudget tblCyhwProjectrBudget : tlist) {
					List<TblCyhwUnit> findListByXdf = this.tblCyhwUnitMapper.selectListByBudgetId(tblCyhwProjectrBudget.getBudgetid());
					List<TblContractSpnode> findListByXdf2 = this.tblCyhwProjectbudgetMapper.selectListByXdf(tblCyhwProjectrBudget.getBudgetid());
					tblCyhwProjectrBudget.setUnitCount(findListByXdf.size());
					tblCyhwProjectrBudget.setPerformanceCount(findListByXdf2.size());
					budgetlist.add(tblCyhwProjectrBudget);
				}
				pageInfo.setTlist(budgetlist);

				Map<String, Object> dataMap = new HashMap<String, Object>(0);
				resultMap.put("data", pageInfo);
				resultMap.put("flow", flow);
				resultMap.put("code", "1");
				resultMap.put("msg", "接口访问成功！");
				resultMap.put("dataMap", dataMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				TblStaffUtil staff = DealUserToken.parseUserToken(token);
				if (staff == null) {
					resultMap.put("code", "0");
					resultMap.put("msg", "用户已失效！");
					return resultMap;
				}

				PageInfo<TblCyhwProjectbudget> pageInfo = new PageInfo<TblCyhwProjectbudget>();

				if (pageSize != null) {
					pageInfo.setPageSize(pageSize);
				}
				if (pageNumber == null) {
					pageNumber = 1;
				}

				pageInfo.setCurrentPage(pageNumber);
				String flowid = "622322";
				TblFlow flow = tblFlowMapper.findById(flowid);
				//TblFlow flow = tblFlowMapper.findFlowInfoByFlowNumber(flowNumber,staff.getCurrentOrg().getOrgid());
				tcpb.setOrgid(staff.getCurrentOrg().getOrgid());
				tcpb.setRecordtype(flow.getFlownumber());
				pageInfo.setCondition(tcpb);
				Integer taskCount = tblProcessAnalysisMapper.getByModuel(flow.getFlownumber(), staff);
				/**
				 * 相对方管理
				 */
//				pageInfo.setCondition(tcpb);
//				if("HTGL001".equals(flow.getFlownumber()) || "HTGL003".equals(flow.getFlownumber()) || "HTGL004".equals(flow.getFlownumber()) || "HTGL006".equals(flow.getFlownumber())) {
//					if(staff.getTrole()!=null && "合同管理员".equals(staff.getTrole().getRname())) {
//						taskCount = 0;
//					}
//				}


				pageInfo.setTlist(tblCyhwProjectbudgetMapper.selectListByPageInfoFlowid(pageInfo, staff, taskCount, flowid));
//				pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.selectCountByPageInfo(pageInfo,staff,taskCount));
				pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.selectListByPageInfoFlowidCount(staff, taskCount, flowid));
				//pageInfo.setTotalRecord(tblCyhwProjectbudgetMapper.selectCountByPageInfoCount(staff,taskCount));
				//关联合同数量+履约数量
				List<TblCyhwProjectbudget> tlist = pageInfo.getTlist();
				List<TblCyhwProjectbudget> budgetlist = new ArrayList<TblCyhwProjectbudget>();
//				Integer contractCount = 0;
//				Integer spNodeCount = 0;
				for (TblCyhwProjectbudget tblCyhwProjectrBudget : tlist) {
					List<TblCyhwUnit> findListByXdf = this.tblCyhwUnitMapper.selectListByBudgetId(tblCyhwProjectrBudget.getBudgetid());
					List<TblContractSpnode> findListByXdf2 = this.tblCyhwProjectbudgetMapper.selectListByXdf(tblCyhwProjectrBudget.getBudgetid());
					tblCyhwProjectrBudget.setUnitCount(findListByXdf.size());
					tblCyhwProjectrBudget.setPerformanceCount(findListByXdf2.size());
					budgetlist.add(tblCyhwProjectrBudget);
				}
				pageInfo.setTlist(budgetlist);

				Map<String, Object> dataMap = new HashMap<String, Object>(0);
				resultMap.put("data", pageInfo);
				resultMap.put("flow", flow);
				resultMap.put("code", "1");
				resultMap.put("msg", "接口访问成功！");
				resultMap.put("dataMap", dataMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		}
	}

    @Override
    public Map<String, Object> projectrBudgettoAdd(BigDecimal flowId, Integer contractId) {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			Map<String, Object> dataMap = new HashMap<String, Object>(0);
			try {
				SimpleDateFormat sdFormat = new SimpleDateFormat("yyyyMMSSS");
				SimpleDateFormat nyr = new SimpleDateFormat("yyyy-MM-dd");
				Calendar cal = Calendar.getInstance();
				java.util.Date date = cal.getTime();
				String myTime = sdFormat.format(date);
				if (flowId != null && flowId.toString().trim().length() > 0) {
					TblFlow flow = tblFlowMapper.findById(flowId.toString());
					dataMap.put("code", flow.getFlownumber() + "_" + myTime);
					if ("HTGL003".equals(flow.getFlownumber()) && contractId != null) {
						TblCyhwUnit unit = this.tblCyhwUnitMapper.getEntity(contractId);
						dataMap.put("unit", unit);
					}
					dataMap.put("searchUrl", ((flow.getFlowmappingurl() == null) ? "/nbkz/cwgl/zcgl_main" : flow.getFlowmappingurl()));
				}
				List<TblCyhwBudetgoods> goodsList = tblCyhwBudetgoodsMapper.findkFirstLevel();
				String createDate = DateUtils.getNowTime("yyyy-MM-dd");
				dataMap.put("createDate", createDate);
				dataMap.put("goodsList", goodsList);
				resultMap.put("code", "1");
				resultMap.put("msg", "接口访问成功！");
				resultMap.put("dataMap", dataMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		} else {
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			Map<String, Object> dataMap = new HashMap<String, Object>(0);
			try {
				SimpleDateFormat sdFormat = new SimpleDateFormat("yyyyMMSSS");
				SimpleDateFormat nyr = new SimpleDateFormat("yyyy-MM-dd");
				Calendar cal = Calendar.getInstance();
				java.util.Date date = cal.getTime();
				String myTime = sdFormat.format(date);
				if (flowId != null && flowId.toString().trim().length() > 0) {
					TblFlow flow = tblFlowMapper.findById(flowId.toString());
					dataMap.put("code", flow.getFlownumber() + "_" + myTime);
					if ("HTGL003".equals(flow.getFlownumber()) && contractId != null) {
						TblCyhwUnit unit = this.tblCyhwUnitMapper.getEntity(contractId);
						dataMap.put("unit", unit);
					}
					dataMap.put("searchUrl", ((flow.getFlowmappingurl() == null) ? "/nbkz/cwgl/zcgl_main" : flow.getFlowmappingurl()));
				}
				List<TblCyhwBudetgoods> goodsList = tblCyhwBudetgoodsMapper.findkFirstLevel();
				String createDate = DateUtils.getNowTime("yyyy-MM-dd");
				dataMap.put("createDate", createDate);
				dataMap.put("goodsList", goodsList);
				resultMap.put("code", "1");
				resultMap.put("msg", "接口访问成功！");
				resultMap.put("dataMap", dataMap);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return resultMap;
		}
    }

	@Override
	public Map<String, Object> getList(String startDate, String orgid) throws Exception {
		if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
			// TODO Auto-generated method stub
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				JSONObject obj = new JSONObject();
				List<JSONObject> list = tblCyhwProjectbudgetMapper.getList(orgid, startDate);
				obj.put("tlist", list);
				resultMap.put("code", "0");
				resultMap.put("msg", "访问成功");
				resultMap.put("data", obj);
			} catch (Exception e) {
				// TODO: handle exception
				resultMap.put("code", "1");
				resultMap.put("msg", "访问失败！");
			}
			return resultMap;
		} else {
			// TODO Auto-generated method stub
			Map<String, Object> resultMap = new HashMap<String, Object>(0);
			try {
				JSONObject obj = new JSONObject();
				List<JSONObject> list = tblCyhwProjectbudgetMapper.getList(orgid, startDate);
				obj.put("tlist", list);
				resultMap.put("code", "0");
				resultMap.put("msg", "访问成功");
				resultMap.put("data", obj);
			} catch (Exception e) {
				// TODO: handle exception
				resultMap.put("code", "1");
				resultMap.put("msg", "访问失败！");
			}
			return resultMap;
		}
	}


//
//	@Override
//	public Map<String, Object> findxdfblInfo(String budgetId, String flowId, String token) {
//		Map<String,Object> resultMap = new HashMap<String, Object>(0);
//		Map<String,Object> dataMap = new HashMap<String,Object>(0);
//		TblStaffUtil staff = null;
//		try {
//			staff = DealUserToken.parseUserToken(token);
//			if(staff == null) {
//				resultMap.put("code", "0");
//				resultMap.put("msg", "用户已失效！");
//				return resultMap;
//			}
//			TblCyhwProjectbudget tcpb = tblCyhwProjectbudgetMapper.findBybudgetId(Integer.parseInt(budgetId));
//
//			TblCirculation	cy = tblCirculationMapper.selectCiculaInfoById(Integer.parseInt(budgetId));
//			List<TblMyTask> list =null;
//			if(staff.getTrole()!= null && staff.getTrole().getRname() != null){
//				dataMap.put("rolename", staff.getTrole().getRname());
//				list= HttpClient.findByTask(staff.getTrole().getRname(), staff.getStaffid().toString(), 1, 1500);
//			}else{
//				list= HttpClient.findByTask("", staff.getStaffid().toString(), 1, 1500);
//			}
//			if(list!=null && list.size()>0){
//				Map<String, Object> map = null;
//				String resultData = null;
//				String[] results = null;
//				for (TblMyTask myTask : list) {
//					if(cy!=null && myTask.getProcessInstanceId().equals(cy.getBusinesskey())){
//						map = HttpClient.lczxProcessJson(myTask.getTaskId());
//						resultData = (String) map.get("data");
//						results = resultData.replace("\"", "").split(",");
//						if(results.length>0 && !results[0].equals("")){
//							List<String> stringB = Arrays.asList(results);
//							dataMap.put("results", stringB);
//							dataMap.put("number", stringB.size());
//						}else{
//							dataMap.put("results", null);
//							dataMap.put("number", 0);
//						}
//						dataMap.put("task", myTask);
//						break;
//					}
//				}
//
//			}
//			if(tcpb.getRecortParent() != null){
//				TblCyhwUnit tcu = tblCyhwUnitService.getEntity(tcpb.getRecortParent());
//				mv.addObject("tcu", tcu);
//				List<TblContractAppendixsigning> signingList = this.tblContractAppendixsigningService.findFileListByContractId(tcu.getContractId());
//				mv.addObject("signingList", signingList);
//			}
//			//相对方外键
//			if(tcpb.getRecordConcat() != null){
//				TblCyhwProjectrBudget tcpb1 = tblCyhwProjectrBudgetService.getEntity(tcpb.getRecortParent());
//				mv.addObject("tcpb1", tcpb1);
//			}
//			//mv.addObject("goodsList", goodsList);
//			//mv.addObject("goodsListCh", goodsListCh);
//			String flowid=request.getParameter("flowid");
//
//			if(flowid==null || flowid==""){
//				flowid= (String) request.getSession().getAttribute("flowid");
//			}
//			if(flowid==null || flowid==""){
//				flowid=tcpb.getFlow().getFlowid().toString();
//			}
//			mv.addObject("flowid",flowid);
//			TblFlow flow = tblFlowService.findById(flowid);
//			mv.addObject("flowname",flow.getFlownumber());
//			String cateId = request.getParameter("cateId");
//			mv.addObject("cy",cy);
//			mv.addObject("cateId",cateId);
//			mv.addObject("tcpb",tcpb);
//			if(user.getTblRole()!=null && user.getTblRole().getRname()!=null){
//				mv.addObject("rolename",user.getTblRole().getRname()!=null);
//			}
//			mv.addObject("v",request.getParameter("v"));
//			mv.setViewName("/nbkz/cyhw/flow_to_sjtzgl_infoyszc");
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		return mv;
//	}
	public TblCyhwProjectbudget findEntityByOutSideId(String outSideId) throws Exception {
		return tblCyhwProjectbudgetMapper.findEntityByOutSideId(outSideId);
	}
}
